﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace esri
{
    namespace ParaSeting
    {
        class Paraseting
        {
            private static Paraseting _instance;
            //Constructer
            protected Paraseting()
            {
            }
            public static Paraseting Instance()
            {
                if (_instance == null)
                    _instance = new Paraseting();
                return _instance;
            }

            //Fields
            private double m_MaxSpeed = 14.4 / 3.6;
            private double m_MinSpeed = 0.72 / 3.6;
            private double m_RollTimes = 8;
            private double m_RollDirection = 67;
            private double m_AngleError = 10;
            private double m_RollWidth = 2;

            public double MaxSpeed
            {
                get { return m_MaxSpeed; }
                set { m_MaxSpeed = value; }
            }
            public double MinSpeed
            {
                get { return m_MinSpeed; }
                set { m_MinSpeed = value; }
            }
            public double RollTimes
            {
                get { return m_RollTimes; }
                set { m_RollTimes = value; }
            }
            public double RollDirection
            {
                get { return m_RollDirection; }
                set { m_RollDirection = value; }
            }
            public double AngleError
            {
                get { return m_AngleError; }
                set { m_AngleError = value; }
            }
            public double RollWidth
            {
                get { return m_RollWidth; }
                set { m_RollWidth = value; }
            }
            ///
            ///保存选中的层、场和范围
            ///
            private string m_strUnitNo;
            public string UnitNo
            {
                get { return  m_strUnitNo; }
                set { m_strUnitNo = value; }
            }

            public double Point_Range;

            public double Point_Grid_Range;
            
        }
    }

    namespace DataBase
    {
        //数据库连接字段设置（使用了Singleton模式）
        class DBConnection
        {
            private static DBConnection _instance;
            //Constructor
            protected DBConnection()
            {
            }
            public static DBConnection Instance()
            {
                if (_instance == null)
                    _instance = new DBConnection();
                return _instance;
            }

            //Fields
            private string m_UserID;
            private string m_Password;
            private string m_DBName;
            private string m_HostName;

            //Attributes
            public string UserID
            {
                get { return m_UserID; }
                set { m_UserID = value; }
            }
            public string Password
            {
                get { return m_Password; }
                set { m_Password = value; }
            }
            public string DBName
            {
                get { return m_DBName; }
                set { m_DBName = value; }
            }
            public string HostName
            {
                get { return m_HostName; }
                set { m_HostName = value; }
            }
            //
            //保存数据库连接的字符串
            //
            private string m_strConn;
            public string ConnectionString
            {
                get { return m_strConn; }
                set { m_strConn = value; }
            }
        }

        //数据库操作
        class DBOperation
        {
            //数据库连接
            private SqlConnection conn;

            //保存数据库连接字符串 SqlConnectionString
            private string strConn;

            /// <summary>
            /// 设置数据库连接字符串
            /// </summary>
            /// <param name="hostname">主机名</param>
            /// <param name="dbname">数据库名</param>
            /// <param name="userid">用户名</param>
            /// <param name="password">密码</param>
            /// <returns>返回连接字符串</returns>

            //设置数据库连接字符串（通过函数重载实现两种不同的连接方式的不同连接字符串）
            public void SetConnString(string hostname, string dbname, string userid, string password)
            {
                strConn = "Integrated Security=false;Persist Security Info=False;server=" + hostname + ";database=" + dbname + ";uid=" + userid + ";pwd=" + password;
            }

            /// <summary>
            /// 设置数据库连接字符串
            /// </summary>
            /// <param name="hostname">主机名</param>
            /// <param name="dbname">数据库名</param>
            /// <returns>返回连接字符串</returns>

            public void SetConnString(string hostname, string dbname)
            {
                strConn = "Integrated Security=SSPI;Persist Security Info=False;server=" + hostname + ";database=" + dbname;
            }

            public string ConnectionString
            {
                get { return strConn; }
                set { strConn = value; }
            }

            //新建数据库连接
            public SqlConnection Connect()
            {
                conn = new SqlConnection(strConn);
                conn.Open();
                return conn;
            }
            public void CloseConnection()
            {
                conn.Close();
            }

            public int GetRowCount(string tablename)
            {
                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection = conn;
                myCommand.CommandType = CommandType.Text;
                myCommand.CommandText = tablename;
                int count = (int)myCommand.ExecuteScalar();
                return count;
            }
        }
    }
    /////////////////////////////////////////////////////////////////////////////
    ///
    ///质量检查
    /// 
    namespace Detect
    {
        class SpeedDirectionDetect
        {
            public struct Grid
            {
                public string FID;
                public double center_x;
                public double center_y;
                public int speed;
                public string direction;
            }
            Grid[] m_Grid;

            public Grid[] GridStatus
            {
                get { return m_Grid; }
                set { m_Grid = value; }
            }

            //保存每个格子的碾压总量的信息
            private struct CarTimes 
            {
                public int iCarNo;
                public int iTimes;
            }
            CarTimes m_CarTimes;

/*
            private struct PointStruct
            {
                public double x;
                public double y;
            }
            PointStruct[] m_Point;
     //       public void InitializePointStruct(double x,double y,int index)
       //     {
         ///       m_Point[index].x = x;
            //    m_Point[index].y = y;
            //}
 */
            //Constructor
            public SpeedDirectionDetect()
            {
            }
            public SpeedDirectionDetect(int gridcount)
            {
                m_Grid = new Grid [gridcount];
            }

            public void InitializeGrid(string ID,double x,double y,int iIndex)
            {
                GridStatus[iIndex - 1].FID = ID;
                GridStatus[iIndex - 1].center_x = x;
                GridStatus[iIndex - 1].center_y = y;
                GridStatus[iIndex - 1].speed = 0;
            }

            public void SpeedDirectionCalculate(object pointarray,double maxspeed,double minspeed,double direction,double angleerror)
            {
                
            }
        }
    }
    
}
